package com.qbd.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.qbd.model.Admin;
import com.qbd.service.AdminService;

@Controller
@RequestMapping("/admin")
public class AdminController {

	@Autowired
	private AdminService adminService;
	
	@RequestMapping("/login")
	public String login(String name,String password,HttpServletRequest request){
		Admin admin=new Admin();
		admin.setName(name);
		admin.setPassword(password);
		Admin admin2=adminService.selectByNameAndPassword(admin);
		if(admin2!=null){
			request.getSession().setAttribute("admin", admin2);
			return "admin/index";
		}else{
			request.getSession().setAttribute("error", "�û������������");
			return "admin/login";
		}
		
	}
	@RequestMapping("/logout")
	public String logout(HttpServletRequest request){
		HttpSession session = request.getSession();
		if (session.getAttribute("admin") != null) {
			session.removeAttribute("admin");
		}
		return "admin/login";
	}
	
	
	@RequestMapping("/admin_top")
	public String admin_top(){
		return "admin/admin_top";
	}
	
	@RequestMapping("/left")
	public String left(){
		return "admin/left";
	}
	
	@RequestMapping("/right")
	public String right(){
		return "admin/right";
	}
	
	@RequestMapping("/dibu")
	public String dibu(){
		return "admin/dibu";
	}
	
	@RequestMapping("/provincelist")
	public String provincelist(){
		return "admin/provincelist";
	}
	
	@RequestMapping("/citylist")
	public String citylist(){
		return "admin/citylist";
	}
	
	@RequestMapping("/arealist")
	public String arealist(){
		return "admin/arealist";
	}
	
	@RequestMapping("/productlist")
	public String productlist(){
		return "admin/productlist";
	}
	
	@RequestMapping("/photolist")
	public String photolist(){
		return "admin/photolist";
	}
	
}
